package com.project.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.EmployeeBean;
import com.project.mapper.IEmployeeMapper;
import com.project.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.List;

@Service
@Transactional
public class EmployeeServiceImpl implements IEmployeeService {
    @Autowired
    private IEmployeeMapper mapper;
    private static final int PAGESIZE=3;
    @Override
    public void addEmployee(EmployeeBean employeeBean) {
        mapper.addEmployee(employeeBean);
    }

    @Override
    public void updateState(int EmployeeId) {
        mapper.updateState(EmployeeId,"离职");
        mapper.updateCompleteDate(EmployeeId, LocalDate.now()+"");
    }

    @Override
    public void updateEmployee(int EmployeeId, String phone, int money) {
        mapper.updateEmployee(EmployeeId, phone, money);
    }

    @Override
    public EmployeeBean findById(int EmployeeId) {
        return mapper.findById(EmployeeId);
    }

    @Override
    public PageInfo<EmployeeBean> cutByItem(int pagNum, String employeeName, String specialty, String state, String rules) {
        PageHelper.startPage(pagNum,PAGESIZE);
        PageInfo<EmployeeBean> info = PageInfo.of
                (mapper.cutByItem(employeeName, specialty, state, rules));
        return info;
    }

    @Override
    public List<EmployeeBean> findNoProject(int projectId, String name, String specialty) {
        return mapper.findNoProject(projectId, name, specialty);
    }

    @Override
    public EmployeeBean findByIdDate(int emId) {
        return mapper.findByIdDate(emId);
    }
}
